package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.auth.login.annotation.NeedLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserListenProcessApiController {

	@Autowired
	private UserListenProcessService userListenProcessService;


	// Request URL: http://localhost:8500/api/user/userListenProcess/getTrackBreakSecond/51953
	@GetMapping("getTrackBreakSecond/{trackId}")
	@Operation(summary = "获取声音播放进度")
	@NeedLogin
	public Result getTrackBreakSecond(
			@PathVariable(value = "trackId") Long trackId) {
		BigDecimal trackBreakSecond = userListenProcessService.getTrackBreakSecond(trackId);
		return Result.ok(trackBreakSecond);
	}

	// Request URL: http://localhost:8500/api/user/userListenProcess/updateListenProcess
	/**
	 * {albumId: "1597", trackId: 51953, breakSecond: 1.748656}
	 * albumId: "1597"
	 * breakSecond: 1.748656
	 * trackId: 51953
	 */
	@PostMapping("updateListenProcess")
	@Operation(summary = "更新声音播放进度，存入MongoDB")
	@NeedLogin
	public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo){
		userListenProcessService.updateListenProcess(userListenProcessVo);
		return Result.ok();
	}

	// Request URL: http://localhost:8500/api/user/userListenProcess/getLatelyTrack
	@NeedLogin
	@Operation(summary = "最近播放")
	@GetMapping("/getLatelyTrack")
	public Result<Map<String,Object>> getRecentlyPlay() {
		Map<String,Object> retMap=userListenProcessService.getRecentlyPlay();
		return Result.ok(retMap);
	}

}

